#include <QtOpenGL>
#include <QVector3D>
#include "cubo.h"

Cubo::Cubo(const QVector3D& center, QObject *parent):
    Object3D(center, parent)
{

}

void Cubo::drawGeometry(void)const
{

    float v[24] = {   -1.0, -1.0,  1.0,
                       1.0, -1.0,  1.0,
                      -1.0,  1.0,  1.0,
                       1.0,  1.0,  1.0,
                      -1.0,  1.0, -1.0,
                       1.0,  1.0, -1.0,
                      -1.0, -1.0, -1.0,
                       1.0, -1.0, -1.0};

    float n[24] = {-0.57735, -0.57735,  0.57735,
                       0.57735, -0.57735,  0.57735,
                      -0.57735,  0.57735,  0.57735,
                       0.57735,  0.57735,  0.57735,
                      -0.57735,  0.57735, -0.57735,
                       0.57735,  0.57735, -0.57735,
                      -0.57735, -0.57735, -0.57735,
                       0.57735, -0.57735, -0.57735};


     origin();
    glColor4f( 0.35, 0.35, 0.35, 1.0);

  glBegin(GL_QUADS);
  {
      //F0
      glNormal3fv(&n[3*0]);
      glVertex3fv(&v[3*0]);

      glNormal3fv(&n[3*1]);
      glVertex3fv(&v[3*1]);

      glNormal3fv(&n[3*3]);
      glVertex3fv(&v[3*3]);

      glNormal3fv(&n[3*2]);
      glVertex3fv(&v[3*2]);

      //F1
      glNormal3fv(&n[3*2]);
      glVertex3fv(&v[3*2]);

      glNormal3fv(&n[3*3]);
      glVertex3fv(&v[3*3]);

      glNormal3fv(&n[3*5]);
      glVertex3fv(&v[3*5]);

      glNormal3fv(&n[3*4]);
      glVertex3fv(&v[3*4]);

      //F2
      glNormal3fv(&n[3*4]);
      glVertex3fv(&v[3*4]);

      glNormal3fv(&n[3*5]);
      glVertex3fv(&v[3*5]);

      glNormal3fv(&n[3*7]);
      glVertex3fv(&v[3*7]);

      glNormal3fv(&n[3*6]);
      glVertex3fv(&v[3*6]);

      //F3
      glNormal3fv(&n[3*6]);
      glVertex3fv(&v[3*6]);

      glNormal3fv(&n[3*7]);
      glVertex3fv(&v[3*7]);

      glNormal3fv(&n[3*1]);
      glVertex3fv(&v[3*1]);

      glNormal3fv(&n[3*0]);
      glVertex3fv(&v[3*0]);

      //F4
      glNormal3fv(&n[3*7]);
      glVertex3fv(&v[3*7]);

      glNormal3fv(&n[3*5]);
      glVertex3fv(&v[3*5]);

      glNormal3fv(&n[3*3]);
      glVertex3fv(&v[3*3]);

      glNormal3fv(&n[3*1]);
      glVertex3fv(&v[3*1]);

      //F5
      glNormal3fv(&n[3*0]);
      glVertex3fv(&v[3*0]);

      glNormal3fv(&n[3*2]);
      glVertex3fv(&v[3*2]);

      glNormal3fv(&n[3*4]);
      glVertex3fv(&v[3*4]);

      glNormal3fv(&n[3*6]);
      glVertex3fv(&v[3*6]);

  }glEnd();
}

void Cubo::origin()const
{
    glDisable(GL_LIGHTING);
    glBegin(GL_LINES);
    glColor3f(1.0, 0, 0);
    glVertex3i(0, 0, 0);
    glVertex3i(1, 0, 0);

    glColor3f(0, 1.0, 0);
    glVertex3i(0, 0, 0);
    glVertex3i(0, 1, 0);

    glColor3f(0, 0, 1.0);
    glVertex3i(0, 0, 0);
    glVertex3i(0, 0, 1);
    glEnd();
    glEnable(GL_LIGHTING);
}
